/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skaitiniai.metodai.perkeltiesMetodas.duomenuSkaitymas;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import skaitiniai.metodai.perkeltiesMetodas.TriistrizaineMatrica;


public class PirmosUzduotiesDuomenuSkaitytuvas {
    private InputStream fstream;
    private final String fname;
    
    public PirmosUzduotiesDuomenuSkaitytuvas(String fname){
        this.fname = fname;
    }
    
    public TriistrizaineMatrica skaitytiDuomenis(){
      
        try {
            TriistrizaineMatrica matrica;
            double a[];
            double b[];
            double c[];
            double d[];
            int n;
            
            FileInputStream fstream = new FileInputStream(fname);
           

            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            
            //A:
            strLine = br.readLine();
            String [] stringElementaiA = strLine.split(" ");
            strLine = br.readLine();
            String [] stringElementaiB = strLine.split(" ");
            strLine = br.readLine();
            String [] stringElementaiC = strLine.split(" ");
            strLine = br.readLine();
            String [] stringElementaiD = strLine.split(" ");
            
            n = stringElementaiB.length;
            
             a = new double[n];
             b =  new double[n];
             c =  new double[n];
             d =  new double[n];
            
            
            for (int i = 0; i < n; i ++){
                a[i] = Double.parseDouble(stringElementaiA[i]);
                b[i] = Double.parseDouble(stringElementaiB[i]);
                c[i] = Double.parseDouble(stringElementaiC[i]);
                d[i] = Double.parseDouble(stringElementaiD[i]);
            }
            
            try {
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(PirmosUzduotiesDuomenuSkaitytuvas.class.getName()).log(Level.SEVERE, null, ex);
            }
            matrica = new TriistrizaineMatrica(a, b, c, d);
            return matrica;
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(PirmosUzduotiesDuomenuSkaitytuvas.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (IOException ex) {
            Logger.getLogger(PirmosUzduotiesDuomenuSkaitytuvas.class.getName()).log(Level.SEVERE, null, ex);
        }
            
        return null;
        
    }
}
